<?php
namespace Home\Controller;
use Think\Controller;
class PassportController extends Controller {
    public function login(){
        C('TOKEN_ON',false);
        if(IS_POST){
            $data['mobile']=I("post.mobile");
            $_POST['pass']=md5(htmlspecialchars_decode(trim(I('post.password'))));
            if($data['mobile'] && I("post.password")){

                $UserInfoModel=D('UserInfo');
                if (!$UserInfoModel->create($_POST)) {
                    $this->error($UserInfoModel->getError());
                }else{
                    $res=$UserInfoModel->where(array('mobile'=>$data['mobile']))->find();
                    if($res && $res['password']==$_POST['pass']){

                        if(I('post.rememberPass')==1){
                            session(array('expire'=>3600*24*90));
                        }
                        session('[regenerate]');
                        session('organ_login',true);
                        session('organ_id',$res['uid']);

                        $this->success('登录成功！',U('Base/building'));
                    }elseif($res && $res['password']!=$data['pass']){
                        $this->error('密码错误！');
                    }else{
                        $this->error('email未注册！');
                    }
                }
            }else{
                $this->error('参数错误！');
            }
        }
    }
}